package com.sunlands.qdcy.tongzhuo.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;

/**
 * @author gaoyanfeng
 * @date 2019/5/2914:21
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "tz_user_diary_zan")
@JsonSerialize
@DynamicUpdate
@DynamicInsert
@ApiModel(value = "日记点赞信息")
public class UserDiaryZanDO {

    @Id
    @GeneratedValue
    @ApiModelProperty(value = "点赞id")
    private Long id;

    @ApiModelProperty(value = "日记id")
    private Long targetId;

    @ApiModelProperty(value = "点赞用户id")
    private Long zanUserId;

    @ApiModelProperty(value = "被点赞用户id")
    private Long zanedUserId;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "1:日记，3:回复")
    private Integer type;

    public enum TypeEnums {
        /**
         * 给日记/回复点赞
         */
        DIARY(1, "日记"),
//        COMMENT(2, "评论"),
        REPLY(3, "回复"),
        ;

        public final Integer code;
        public final String desc;

        TypeEnums(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public static UserDiaryZanDO.TypeEnums create(Integer code) {
            if (null == code) {
                return null;
            }
            for (UserDiaryZanDO.TypeEnums field : UserDiaryZanDO.TypeEnums.values()) {
                if (code.intValue() == field.getCode()) {
                    return field;
                }
            }
            return null;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }
}
